#include <utl/vector.h>
#include <utl/input.h>

namespace input
{
	namespace detail
	{
		utl::vector<input_system_base*> input_callbacks{};
		utl::vector<input_callback> input_callback_fns{};
	}
	namespace
	{
		input_value input_values[input_code::max]{};
	
		enum modifier_flags : u8
		{
			left_shift = 0x10,
			left_ctrl = 0x20,
			left_alt = 0x40,

			right_shift = 0x10,
			right_ctrl = 0x20,
			right_alt = 0x40,

			none
		};

		u8 modifier_keys_state{ 0 };
	}

	void get_input( input_code code, input_value& value)
	{
		value = input_values[code];
	}

	void set_input( input_code code, input_value_type value)
	{
		input_value& current_input{ input_values[code] };
		current_input.previous = current_input.current;
		current_input.current = value;
		for (auto& item : detail::input_callbacks)
		{
			item->on_event(code, current_input);
		}
		for(auto& item : detail::input_callback_fns)
		{
			item(code, current_input);
		}
	}

	void register_callback(input_callback cbk)
	{
		detail::input_callback_fns.push_back(cbk);
	}

	detail::input_system_base::input_system_base()
	{
		input_callbacks.push_back(this);
	}

	detail::input_system_base::~input_system_base()
	{
		utl::vector_delete_element(input_callbacks,this);
	}
}


